<?php
$conn=mysql_connect("localhost","root","gsda1.mysql1");
//$conn=mysql_connect("localhost","root","");
mysql_select_db("gsdai", $conn);
mysql_query("SET character_set_results = 'gbk', character_set_client = 'gbk', character_set_connection = 'gbk', character_set_database = 'gbk', character_set_server = 'gbk'", $conn);

$sql = "select * from dw_borrow";

$result = db_fetch_arrays($sql, $conn);
$index = 0;
foreach ($result as $key => $value){
	$index++;
	$borrow_id = $value['id'];
	$isday = (isset($value['isday']) && $value['isday']!=''?$value['isday']:0);
	$addtime = (isset($value['addtime']) && $value['addtime']!=''?$value['addtime']:0);
	$sql1 = "update ych_borrow set add_time={$addtime},is_day={$isday} where id={$borrow_id}";
	mysql_select_db("new_gsdai", $conn);
	mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $conn);
	$query = mysql_query($sql1, $conn);
	if(!$query){
		echo $sql1;
		exit;
	}
}
echo $index;

function db_fetch_arrays($sql, $conn) 	{
	$result = mysql_query($sql, $conn);
	$i = 0;
	$_res = array();
	while($res = mysql_fetch_array($result,MYSQL_ASSOC)) {
		foreach ($res as $key => $value){
			$_res[$i][$key] = $value;//直接转义
		}
		$i++;
	}
	return $_res;
}
